﻿using ConfExpert.Forms.Base;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
using Extensions;
using System;

namespace ConfExpert.Forms.Sistem
{
    public partial class Izinler : XForm
    {
        public Izinler()
        {
            InitializeComponent();
        }

        RepositoryItemComboBox riAksiyon
        {
            get
            {
                RepositoryItemComboBox ri = new RepositoryItemComboBox();
                ri.TextEditStyle = TextEditStyles.DisableTextEditor;
                ri.Items.AddRange(new object[] { "Raporlu", "Yıllık İzin", "Ücretli İzin", "Ücretsiz İzin", "Mazeret" });
                return ri;
            }
        }

        private void Izinler_Load(object sender, EventArgs e)
        {
            gridView1.Init("GetPDKSIzin");
            gridView1.AddDetailGrid(gridView2, "KartNo");
            gridView2.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;
            gridView2.Columns["Tur"].ColumnEdit = riAksiyon;
            gridView2.SutunEkle("Iz", typeof(DateTime), "ISNULL(IzinBitis, IzinBaslangic)");
            gridView2.MakeColumnInvisible("Iz");

            gridView1.SutunEkle("SonIzin", typeof(DateTime), "MAX(Child({FK}).Iz)");
            gridView1.FormatAsDate("SonIzin");
            gridView1.AddSummary();
            gridView2.MakeColumnInvisible("PDKSIzinId");
            gridView2.SetCaptions("IzinBaslangic:Başl. Gün", "IzinBitis:Bitiş Gün", "IzinBaslangicSaat:Başl. Saat", "IzinBitisSaat:Bitiş Saat");
            gridView2.FormatAsDate("IzinBaslangic", "IzinBitis");

            //RepositoryItemTimeSpanEdit ri2x = new RepositoryItemTimeSpanEdit();
            //RepositoryItemTimeEdit ri2x = new RepositoryItemTimeEdit();
            //ri2x.Mask.EditMask = "HH:mm";
            //ri2x.Mask.UseMaskAsDisplayFormat = true;
            //ri2x.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
            //ri2x.ExportMode = DevExpress.XtraEditors.Repository.ExportMode.DisplayText;

            //foreach (string col in "IzinBaslangicSaat IzinBitisSaat".Split(" ".ToCharArray()))
            //    gridView2.Columns[col].ColumnEdit = ri2x;

            gridView1.BestFitColumns();
            gridView2.BestFitColumns();

            splitContainerControl1.AutoSize();
            btnKaydet.ItemClick += btnKaydet_ItemClick;

            gridView1.FocusedRowChanged += GridView1_FocusedRowChanged;
        }

        private void GridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            gridView2.BestFitColumns();
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView2.EndEdit();
            gridView2.Update();
        }
    }
}
